<template>
<div class="withdrawal-application views-container">
    <el-dialog :visible.sync="dialogVisibleImg" width="30%" custom-class="reset-pwd wlm-form-dialog dialog-table">
        <div class="wlm-form">
            <div class="wlm-form-header wlm-dialog-fixheader">
                <span class="wlm-dialog-inlenr">驳回原因</span>
            </div>
            <p style="padding:20px;min-height:200px">{{openDialogText}}</p>
        </div>
    </el-dialog>

    <el-dialog v-if="dialogTableType === 'WithdrawToExamine'" @close="resetDialogFormData" :visible.sync="dialogTableVisible" custom-class="reset-pwd wlm-form-dialog dialog-table">
        <div class="wlm-form" v-if="dialogTableVisible">
            <div class="wlm-form-header wlm-dialog-fixheader">
                <span class="wlm-dialog-inlenr">审核</span>
            </div>
            <el-scrollbar wrap-class="scrollbar-wrapper">
                <div class="wlm-form-content">
                    <div class="wlm-dialog-main">
                        <div class="wlm-dialog-content">
                            <el-form ref="userForm" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
                                <el-form-item label="审核状态" prop="name">
                                    <el-radio-group v-model="formFormatData.formData.status">
                                        <!-- <el-radio label="10">待审核</el-radio> -->
                                        <el-radio label="2">审核通过</el-radio>
                                        <el-radio label="4">驳回</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                                <el-form-item label="原因" prop="merchantlog" v-if="formFormatData.formData.status=='4'">
                                    <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 4}" v-model.trim="formFormatData.formData.reason">
                                    </el-input>
                                </el-form-item>
                            </el-form>
                        </div>
                    </div>
                </div>
            </el-scrollbar>
        </div>
        <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
            <el-button size="small" type="primary" @click="saveContent">确定</el-button>
        </footer>
    </el-dialog>

    <div class="wlm-table">
        <div class="wlm-table-header" style="margin-bottom:20px;">
            <div class="dashboard-header">
                <el-row type="flex" :gutter="20" justify="space-between">
                    <el-col :span="4">
                        <div class="dashboard-header-item flex-col flex-justify-c flex-align-c">
                            <div class="item-title">提现总金额</div>
                            <div class="item-num">
                                <span class="text-danger">￥</span><span>{{tableFormatData.userTable.otherData.tx_sum}}</span>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="4">
                        <div class="dashboard-header-item flex-col flex-justify-c flex-align-c">
                            <div class="item-title">已打款金额</div>
                            <div class="item-num">
                                <span class="text-danger">￥</span><span>{{tableFormatData.userTable.otherData.ytx_sum}}</span>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="4">
                        <div class="dashboard-header-item flex-col flex-justify-c flex-align-c">
                            <div class="item-title">提现总用户</div>
                            <div class="item-num">
                                <span>{{tableFormatData.userTable.otherData.tx_sum_num}}</span>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="4">
                        <div class="dashboard-header-item flex-col flex-justify-c flex-align-c">
                            <div class="item-title">处理中金额</div>
                            <div class="item-num">
                                 <span class="text-danger">￥</span><span>{{tableFormatData.userTable.otherData.tx_sum_on?tableFormatData.userTable.otherData.tx_sum_on:0}}</span>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="4">
                        <div class="dashboard-header-item flex-col flex-justify-c flex-align-c ">
                            <div class="item-title">已驳回金额</div>
                            <div class="item-num">
                                 <span class="text-danger">￥</span><span>{{tableFormatData.userTable.otherData.w_tx_sum?tableFormatData.userTable.otherData.w_tx_sum:0}}</span>
                            </div>
                        </div>
                    </el-col>
                </el-row>
            </div>
        </div>
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="80px" class="retail-form" label-position="right">
                <el-form-item label="" class="filter">
                    <el-form-item label="用户：" class="search">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.withdrawal_name" style="width:160px;"></el-input>
                    </el-form-item>
                    <el-form-item label="提现方式：" class="search">
                        <el-select v-model="tableFormatData.userTable.files.withdrawal_type" placeholder="请选择">
                            <el-option v-for="item in [{lable:'全部',value:''},{lable:'微信',value:'wechat'}]" :key="item.value" :label="item.lable" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <el-tabs v-model="tableFormatData.userTable.files.status" type="card" @tab-click="filesSerch">
            <!-- @tab-click="filesSerch" -->
            <el-tab-pane label="全部申请" name="0"></el-tab-pane>
            <el-tab-pane label="待审核" name="1"></el-tab-pane>
            <el-tab-pane label="待打款" name="2"></el-tab-pane>
            <el-tab-pane label="已打款" name="3"></el-tab-pane>
            <el-tab-pane label="已驳回" name="4"></el-tab-pane>
        </el-tabs>
        <div class="wlm-table-content">
            <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <!-- <el-table-column v-if="tableFormatData.userTable.files.apply_status == '20' || tableFormatData.userTable.files.apply_status == '10'" type="selection" width="55">
                </el-table-column> -->
                <el-table-column prop="withdrawal_name" label="姓名" min-width="40">
                </el-table-column>
                <el-table-column prop="name" label="提现方式" min-width="35">
                    <template slot-scope="scope">
                        <span>{{scope.row.withdrawal_type=='wechat'?'微信':scope.row.withdrawal_type=='aliapp'?'支付宝':'银行卡'}}</span>
                        <el-popover trigger="hover" placement="top" v-if="scope.row.withdrawal_type=='card'">
                            <div>
                                <p>银行：{{scope.row.bank_name}}</p>
                                <!-- <p>卡号：{{scope.row.bank_card}}</p>
                                <p>手机号：{{scope.row.mobile}}</p> -->
                            </div>
                            <span style="cursor: pointer;margin-left:6px;" slot="reference"><i class="el-icon-warning orders-blue"></i></span>
                        </el-popover>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="申请金额" min-width="33">
                    <template slot-scope="scope">
                        <span class="text-danger">￥{{scope.row.apply_pay}}
                        </span>
                        <!-- <el-tooltip class="item" effect="dark" :content="sourceType[`${scope.row.source}`]" placement="top">
                            <img height="20" width="20" :src="sourceImg[`${scope.row.source || '--'}`]" alt="">
                        </el-tooltip> -->
                    </template>
                </el-table-column>

                <el-table-column prop="settlement_pay" label="手续费" min-width="33">
                    <template slot-scope="scope">
                        <span class="text-danger">￥{{scope.row.settlement_pay}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="deserved_pay" label="到账" min-width="33">
                    <template slot-scope="scope">
                        <span class="text-danger">￥{{scope.row.deserved_pay}}
                        </span>
                    </template>
                </el-table-column>>
                <el-table-column prop="name" label="申请状态" min-width="45">
                    <template slot-scope="scope">
                        <span v-if="scope.row.status==1">待审核</span>
                        <span v-if="scope.row.status==2">待打款</span>
                        <span v-if="scope.row.status==4">驳回</span>
                        <span v-if="scope.row.status==3">已打款</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="申请时间" min-width="48">
                    <template slot-scope="scope">
                        <span>{{ scope.row.create_time}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="审核时间" min-width="48">
                    <template slot-scope="scope">
                        <span>{{ scope.row.update_time || '-' }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" min-width="62">
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <el-button v-if="scope.row.status==1" class="wlm-text" type="text" @click="changeFormatType('WithdrawToExamine');formFormatDialogEditEvt({redirect:'ids',id:[scope.row.id],toggle:'dialogTableVisible',noEdit:true})">审核</el-button>
                            <el-button v-if="scope.row.status==2" class="wlm-text" type="text" @click="changeTableItem({id:scope.row.id,type:2,status:3},tableFormatData.userTable.change.flag,{isWarning: true,warning:'是否标记已打款？',cancel:'已取消'})">标记打款</el-button>
                            <div v-if="scope.row.status==2" class="btn-line"></div>
                            <el-button v-if="scope.row.status==2" class="wlm-text" type="text" @click="changeTableItem({id:scope.row.id,type:1,status:3},tableFormatData.userTable.change.refund,{isWarning: true,warning:'是否确认打款？',cancel:'已取消'})">确认打款</el-button>
                            <el-button v-if="scope.row.status==4" class="wlm-text" type="text" @click="openDialog(scope.row.reason)">驳回原因</el-button>
                            <span v-if="scope.row.status==3">-</span>
                            <!-- <el-button v-if="scope.row.status==3" class="wlm-text" type="text" @click="openDialog(scope.row.reason)">驳回原因</el-button> -->
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-b flex-align-c">
                <!-- <el-row class="pagination-btns">
                    <el-checkbox class="check-all" v-if="tableFormatData.userTable.files.apply_status == '20' || tableFormatData.userTable.files.apply_status == '10'" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" v-if="tableFormatData.userTable.files.apply_status == '20'" :disabled="isGroup" @click="changeTableItem({isGroup:true},tableFormatData.userTable.change.refund,{isWarning: true,warning:'是否确认打款？',cancel:'已取消'})" type="primary" size="mini">批量打款</el-button>
                    <el-button class="right-8" v-if="tableFormatData.userTable.files.status == 1" :disabled="isGroup" size="mini" @click="auditBatch">批量审核</el-button>
                </el-row> -->
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  regApplyTx,
  regApplyTxSh,
  regApplyTxMakeMoney
} from '@/api/commityBuy'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table'), mixins.getters('Form')],
  name: 'WithdrawalApplication',
  components: {

  },
  created() {
  },
  data() {
    return {
      dialogTableVisible: false,
      dialogTableType: 'WithdrawToExamine',
      categoryData: {},
      dialogVisibleImg: false,
      openDialogText: '',
      userInfo: {
        nickName: '',
        user_id: '',
        avatarUrl: ''
      },
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: regApplyTx,
            delList: 1,
            msgConfig: {
              del: {
                type: 'warning',
                msg: '是否确认删除团购提现申请？'
              }
            }
          },
          tableData: [],
          files: {
            withdrawal_name: '',
            withdrawal_type: '',
            status: 0,
            ids: [],
            checkall: '0',
            Recycle: '1'
          },
          otherData: {},
          change: {
            refund: {
              name: '确认打款',
              key: 'refund',
              api: regApplyTxMakeMoney
            },
            flag: {
              name: '标记打款',
              key: 'refund',
              api: regApplyTxMakeMoney
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      },
      formFormatData: {
        key: 'userForm',
        model: {
          noCreateEdit: false,
          bindDialog: 'dialogTableVisible'
        },
        api: {
          editForm: {
            api: 1,
            params: {
              id: ''
            },
            redirect: 'ids'
          },
          submitForm: 1
        },
        formData: {
          ids: [],
          content: '',
          status: '2'
        },
        rules: {}
      }
    }
  },
  methods: {
    formPageChange(page) {
      this.formFormatData.api.editForm.params.page = page
      this.formFormatEditEvt(true)
    },
    changeFormatType(type) {
      this.dialogTableType = type
      switch (type) {
        case 'WithdrawToExamine':
          this.formFormatData = {
            key: 'userForm',
            model: {
              noCreateEdit: false,
              bindDialog: 'dialogTableVisible'
            },
            api: {
              editForm: {
                api: regApplyTxSh,
                params: {
                  id: ''
                },
                redirect: 'ids'
              },
              submitForm: regApplyTxSh
            },
            formData: {
              ids: [],
              reason: '',
              status: '3'
            },
            rules: {}
          }
          break
      }
    },
    openDialog(params) {
      this.openDialogText = params
      this.dialogVisibleImg = true
    },
    changeTableCallBack(params) {

    },
    saveContent() {
      this.formFormatSubmit()
    },
    auditBatch() {
      var array = []
      this.tableFormatData.userTable.files.ids.map((item) => {
        array.push(item.id)
      })
      this.formFormatDialogEditEvt({ id: array, toggle: 'dialogTableVisible', noEdit: true })
    }
  }
}
</script>

<style lang="scss" scoped>
.withdrawal-application {}
</style>
